package com.FH.organization.peopleCrp;

import com.FH.organization.Attachment.AttachmentResource;
import com.FH.organization.department.DepartmentResource;
import com.FH.organization.department.DepartmentShowDTO;
import com.FH.permission.member_role.MemberRoleResource;
import com.FH.permission.privilege_menu.PrivilegemenuResource;
import com.FH.util.*;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

import javax.ejb.Stateless;
import javax.inject.Inject;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * Created by jinweizhe on 16/6/23.
 */
@Stateless
public class KamMemberCrpDAOImpl extends AccessDB implements KamMemberCrpDAO {

    @Inject
    PrivilegemenuResource privilegemenuResource;

    @Inject
    MemberRoleResource memberRoleResource;

    @Inject
    DepartmentResource departmentResource;
    @Inject
    AttachmentResource attachmentResource;
    /**
     * 登录获取用户信息方法
     *
     * @param member_name
     * @return
     */
    @Override
    public ResultDTO getLoginInfo(String member_name, String password) {

        String existName = "0";

        //判断用户名是否存在
        if (null != member_name && !"".equals(member_name)) {

            String sqlexit = "select count(1) from kam_member where nickname = '" + member_name + "'";

            existName = getReportingToOne(sqlexit);
        }


        List<String[]> seresult = new ArrayList<String[]>();

        List<KamMemberCrpShowDTO> result = new ArrayList<KamMemberCrpShowDTO>();

        if (!existName.equals("0")) {

            //登录sql语句
            String sql = "select k.member_id,k.member_code,k.nickname,k.member_name,k.member_password,k.member_gender," +
                    "k.member_birthday,k.member_phone,k.member_id_card,k.PROVINCE_ID,p.PROVINCE_NAME," +
                    "k.CITY_ID,c.CITY_NAME,k.organization_id,o.organization_name,h.head_portrait_add,k.REGISTER_DATE,k.UP_DATE,k.member_email,k.vacationyeardays,k.onvacationdays" +
                    " from kam_member k " +
                    "left join head_portrait h " +
                    "on k.head_portrait_ID = h.head_portrait_id " +
                    "left join province_info p " +
                    "on p.PROVINCE_ID = k.PROVINCE_ID " +
                    "left join city_info c " +
                    "on c.CITY_ID = k.CITY_ID " +
                    "left join organization o " +
                    "on o.organization_id = k.organization_id " +
                    "where k.nickname = '" + member_name + "' or k.member_phone = '" + member_name + "'";

            seresult = this.getReportingTo(sql);

            //构建返回对象
            for (int i = 0; i < seresult.size(); i++) {
                System.out.println(seresult.get(i)[0]);
                KamMemberCrpShowDTO news = new KamMemberCrpShowDTO();
                news.setMember_id(seresult.get(i)[1]);
                news.setMember_code(seresult.get(i)[2]);
                news.setNickname(seresult.get(i)[3]);
                news.setMember_name(seresult.get(i)[4]);
                news.setMember_password(seresult.get(i)[5]);
                news.setMember_gender(seresult.get(i)[6]);
                news.setMember_birthday(seresult.get(i)[7]);
                news.setMember_phone(seresult.get(i)[8]);
                news.setMember_id_card(seresult.get(i)[9]);
                news.setProvince_id(seresult.get(i)[10]);
                news.setProvince_name(seresult.get(i)[11]);
                news.setCity_id(seresult.get(i)[12]);
                news.setCity_name(seresult.get(i)[13]);
                news.setOrganization_id(seresult.get(i)[14]);
                news.setOrganization_name(seresult.get(i)[15]);
                news.setHeadimage_url(seresult.get(i)[16]);
                news.setRegister_date(seresult.get(i)[17]);
                news.setUp_date(seresult.get(i)[18]);
                news.setMember_email(seresult.get(i)[19]);
                news.setVacationyeardays(seresult.get(i)[20]);
                news.setOnvacationdays(seresult.get(i)[21]);
                ResultDTO userlist = null, departmentinfo = null;
                userlist = memberRoleResource.getOfficeInfo("{member_id:" + seresult.get(i)[1] + "}", "1", "10");
                news.setSysrolelsit(userlist.getValues());
                departmentinfo = departmentResource.getDepartmentInfo("{organization_id:" + seresult.get(i)[14] + "}", "1", "1");
                news.setDepartmentShowDTOList(departmentinfo.getValues());
                result.add(news);
            }
        }


        ResultDTO resultDTO = new ResultDTO();

        if (seresult.size() != 0) {
            resultDTO.setStatus("90000");//
            resultDTO.setDescritpion("用户信息调用成功");
        } else {
            resultDTO.setStatus("90001");//
            resultDTO.setDescritpion("用户不存在");
        }

        resultDTO.setValues(result);
        System.out.println(resultDTO);

        return resultDTO;
    }


    /**
     * 获取用户列表信息
     *
     * @param search
     * @param page
     * @param size
     * @return
     */
    @Override
    public ResultDTO getUserListInfo(String search, String page, String size) {

        ResultDTO resultDTO = new ResultDTO();
        try {
            JSONObject json_search = new JSONObject(search);

            String existName = "0";
            String sql_w = "";

            if (json_search.has("organization_id")) {
                sql_w += " AND k.organization_id='" + json_search.getString("organization_id") + "'";
            }

            if (json_search.has("member_id")) {
                sql_w += " AND k.member_id = '" + json_search.getString("member_id") + "'";
            }

            String sqlexit = "select count(1) from kam_member as k where 1=1 " + sql_w + " limit " + page + "," + size;


            existName = getReportingToOne(sqlexit);

            List<String[]> seresult = new ArrayList<String[]>();

            List<KamMemberCrpShowDTO> result = new ArrayList<KamMemberCrpShowDTO>();


            if (!existName.equals("0")) {

                //登录sql语句
                String sql = "select k.member_email, k.member_id,k.member_code,k.nickname,k.member_name,k.member_password,k.member_gender," +
                        "k.member_birthday,k.member_phone,k.member_id_card,k.PROVINCE_ID,p.PROVINCE_NAME," +
                        "k.CITY_ID,c.CITY_NAME,k.organization_id,o.organization_name,h.head_portrait_add,k.REGISTER_DATE,k.UP_DATE,k.member_email_psw,k.vacationyeardays,k.onvacationdays,k.attachment_id" +
                        " from kam_member k " +
                        "left join head_portrait h " +
                        "on k.head_portrait_ID = h.head_portrait_id " +
                        "left join province_info p " +
                        "on p.PROVINCE_ID = k.PROVINCE_ID " +
                        "left join city_info c " +
                        "on c.CITY_ID = k.CITY_ID " +
                        "left join organization o " +
                        "on o.organization_id = k.organization_id " +
                        "WHERE 1=1" + sql_w;

                seresult = this.getReportingTo(sql);

                //构建返回对象
                for (int i = 0; i < seresult.size(); i++) {
                    System.out.println(seresult.get(i)[0]);
                    KamMemberCrpShowDTO news = new KamMemberCrpShowDTO();
                    news.setMember_email(seresult.get(i)[1]);
                    news.setMember_id(seresult.get(i)[2]);
                    news.setMember_code(seresult.get(i)[3]);
                    news.setNickname(seresult.get(i)[4]);
                    news.setMember_name(seresult.get(i)[5]);
                    news.setMember_password(seresult.get(i)[6]);
                    news.setMember_gender(seresult.get(i)[7]);
                    news.setMember_birthday(seresult.get(i)[8]);
                    news.setMember_phone(seresult.get(i)[9]);
                    news.setMember_id_card(seresult.get(i)[10]);
                    news.setProvince_id(seresult.get(i)[11]);
                    news.setProvince_name(seresult.get(i)[12]);
                    news.setCity_id(seresult.get(i)[13]);
                    news.setCity_name(seresult.get(i)[14]);
                    news.setOrganization_id(seresult.get(i)[15]);
                    news.setOrganization_name(seresult.get(i)[16]);
                    news.setHeadimage_url(seresult.get(i)[17]);
                    news.setRegister_date(seresult.get(i)[18]);
                    news.setUp_date(seresult.get(i)[19]);
                    news.setMember_email_psw(seresult.get(i)[20]);
                    news.setVacationyeardays(seresult.get(i)[21]);
                    news.setOnvacationdays(seresult.get(i)[22]);
                    news.setOnvacationdays(seresult.get(i)[23]);
                    ResultDTO departmentinfo = null;
                    departmentinfo = departmentResource.getDepartmentInfo("{organization_id:" + seresult.get(i)[15] + "}", "1", "1");
                    news.setDepartmentShowDTOList(departmentinfo.getValues());


                    ResultDTO attach2 = null;
                    if (seresult.get(i)[23] != null && !seresult.get(i)[23].equals("")) {
                        attach2 = attachmentResource.getAttachmentInfo("{attachment_id:" + seresult.get(i)[23] + "}", "1", "1");
                        news.setImages(attach2.getValues());
                    }
                    result.add(news);
                }
            }


//            if(!existName.equals("0")){
//
//                //登录sql语句
//                String sql = "SELECT member_id,member_code,member_name,nickname,member_password,member_gender,member_birthday,member_phone,member_id_card,province_id," +
//                        "city_id,organization_id,register_date,up_date FROM kam_member WHERE 1=1" +sql_w + " limit "+page+","+size;
//
//                seresult = this.getReportingTo(sql);
//
//                //构建返回对象
//                for (int i = 0; i < seresult.size(); i++){
//
//                    KamMemberShowDTO km = new KamMemberShowDTO();
//                    km.setMember_id(seresult.get(i)[1]);
//                    km.setMember_code(seresult.get(i)[2]);
//                    km.setMember_name(seresult.get(i)[3]);
//                    km.setNickname(seresult.get(i)[4]);
//                    km.setMember_password(seresult.get(i)[5]);
//                    km.setMember_gender(seresult.get(i)[6]);
//                    km.setMember_birthday(seresult.get(i)[7]);
//                    km.setMember_phone(seresult.get(i)[8]);
//                    km.setMember_id_card(seresult.get(i)[9]);
//                    km.setProvince_id(seresult.get(i)[10]);
//                    km.setCity_id(seresult.get(i)[11]);
//                    km.setOrganization_id(seresult.get(i)[12]);
//                    km.setRegister_date(seresult.get(i)[13]);
//                    km.setUp_date(seresult.get(i)[14]);
//
//                    result.add(km);
//                }
//            }

            if (seresult.size() != 0) {
                resultDTO.setStatus("90000");//
                resultDTO.setDescritpion("用户列表信息调用成功");
            } else {
                resultDTO.setStatus("90001");//
                resultDTO.setDescritpion("用户列表信息调用失败");
            }
            resultDTO.setValues(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return resultDTO;
    }

    //根据用户单个id删除单个用户信息
    @Override
    public ResultDTO deleteKamMemberInfo(String str) {

        ResultDTO resultDTO = null;
        try {
            JSONObject jsonObject = new JSONObject(str);
            String userId  = jsonObject.getString("userId");

            String sql = "select count(1) from kam_member where userId ='" + userId + "'";

            String existName = getReportingToOne(sql);

            int result = 0;

            resultDTO = new ResultDTO();

            if (existName != null) {

                String QUERY = "delete from kam_member where userId ='" + userId + "'";

                result = this.addReportingTo(QUERY);


            }

            if (result != 0) {
                resultDTO.setStatus("90000");
                resultDTO.setDescritpion("调用成功，删除成功！");
            } else {
                resultDTO.setStatus("90001");
                resultDTO.setDescritpion("调用失败。删除失败！");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return resultDTO;
    }

    /**
     * 通过member_id修改用户信息
     *
     * @param str
     * @return
     */
    @Override
    public ResultDTO updateKamMemberInfo(String str) {


        ResultDTO resultDTO = new ResultDTO();
        try {
            JSONObject jsonObject = new JSONObject(str);

            String member_email = jsonObject.has("member_email")?jsonObject.getString("member_email"):null;
            String member_name = jsonObject.has("member_name")?jsonObject.getString("member_name"):null;
            String loginId = jsonObject.has("loginId")?jsonObject.getString("loginId"):null;
            String member_phone = jsonObject.has("member_phone")?jsonObject.getString("member_phone"):null;
            String nickname = jsonObject.has("nickname")?jsonObject.getString("nickname"):null;
            String passWord = jsonObject.has("passWord")?jsonObject.getString("passWord"):null;
            String UserId = jsonObject.has("userId")?jsonObject.getString("userId"):null;
            String member_id_card = jsonObject.has("member_id_card")?jsonObject.getString("member_id_card"):null;
            String bank_account = jsonObject.has("bank_account")?jsonObject.getString("bank_account"):null;
            String Id = String .valueOf(UserId);
            String orgId = jsonObject.has("orgId")?jsonObject.getString("orgId"):null;

            String organization_id = "";
            if(null!=orgId&&!"".equals(orgId.trim())){
                List<DepartmentShowDTO> departmentShowDTOs = departmentResource.getDepartmentInfo("{base_org_id:"+orgId+"}","1","1").getValues();

                organization_id = departmentShowDTOs.get(0).getOrganization_id();
            }

        String membername = "select count(1) from kam_member WHERE userId='" + Id + "'";

        String existName = getReportingToOne(membername);

        int resultls = 0;

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = df.format(new Date());

        //构建返回对象

        if (!existName.equals("0")) {
            String QUERY = "";
            QUERY += "update kam_member set register_date='" + time + "'";
            if (null != member_name && !"".equals(member_name)) {
                QUERY += ",member_name='" + member_name + "'";
            }

            if (null != nickname && !"".equals(nickname)) {
                QUERY += ",nickname='" + nickname + "'";
            }
            if (null != passWord && !"".equals(passWord)) {
                QUERY += ",member_password='" + passWord + "'";
            }
            if (null != member_phone && !"".equals(member_phone)) {
                QUERY += ",member_phone='" + member_phone + "'";
            }
            if (null != member_email && !"".equals(member_email)) {
                QUERY += ",member_email='" + member_email + "'";
            }
            if (null != organization_id && !"".equals(organization_id)) {
                QUERY += ",organization_id='" + organization_id + "'";
            }
            if (null != member_id_card && !"".equals(member_id_card)) {
                QUERY += ",member_id_card='" + member_id_card + "'";
            }
            if (null != bank_account && !"".equals(bank_account)) {
                QUERY += ",bank_account='" + bank_account + "'";
            }

            QUERY += "  where userId='" + Id + "'";

            resultls = addReportingTo(QUERY);
        }


        if (resultls != 0) {
            resultDTO.setStatus("90000");
            resultDTO.setDescritpion("用户信息修改成功");

        } else {
            resultDTO.setStatus("90001");
            resultDTO.setDescritpion("用户信息修改失败");
        }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return resultDTO;
    }

    //用户注册
    @Override
    public ResultDTO addKamMember(String str) {

        String ORG_MEMBER = "";
        ResultDTO resultDTO = new ResultDTO();
        try {
        JSONObject jsonObject = new JSONObject(str);

            String member_email = jsonObject.getString("member_email");
            String member_name = jsonObject.getString("member_name");
            String member_phone = jsonObject.getString("member_phone");
            String nickname = jsonObject.getString("nickname");
            String member_password = jsonObject.getString("passWord");
            String member_gender = jsonObject.getString("member_gender");
            String userId = jsonObject.getString("userId");
            String member_id_card = jsonObject.has("member_id_card")?jsonObject.getString("member_id_card"):"";
            String bank_account = jsonObject.has("bank_account")?jsonObject.getString("bank_account"):"";
            String fhId = String .valueOf(userId);
            String orgId = jsonObject.has("orgId")?jsonObject.getString("orgId"):null;

            String organization_id = "";
            if(null!=orgId&&!"".equals(orgId.trim())){
                List<DepartmentShowDTO> departmentShowDTOs = departmentResource.getDepartmentInfo("{base_org_id:"+orgId+"}","1","1").getValues();

                organization_id = departmentShowDTOs.get(0).getOrganization_id();
            }

            //构建返回对象


            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");

            //判读用户电话是否存在
            String sql1 = "select count(1) from kam_member where member_name = '" + member_name + "' ";

            String existMember = getReportingToOne(sql1);

            if(!existMember.equals("0")){
                return updateKamMemberInfo(str);
            }

            String idcard = "";


            int resultls = 0;

            if (!existMember.equals("1")) {

                //构建插入sql
                ORG_MEMBER += "insert into kam_member(member_id,member_name,nickname,member_password,member_gender," +
                        "member_phone,register_date,member_email,userId,member_id_card,bank_account,organization_id) VALUES('" +
                        uuid + "','" + member_name + "','" + nickname + "','" +
                        MD5.MD5ThreeTwo(member_password) + "','" + (member_gender.equals("man")?1:0) + "','" +
                        member_phone + "','" + df.format(new Date()) + "','" +
                        member_email + "','" + fhId + "','" + member_id_card+ "','" + bank_account+ "','" + organization_id+"')";

                //插入业务表
                resultls = addReportingTo(ORG_MEMBER);
            }


            if (resultls != 0) {
                resultDTO.setStatus("90000");//
                resultDTO.setDescritpion("用户注册成功");



            } else {
                resultDTO.setStatus("90001");//
                resultDTO.setDescritpion("用户注册失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultDTO;
    }

    /**
     * 多级查询，返回菜单信息
     * 从人员—角色—权限—菜单
     * 一一返回出来
     *
     * @param apply
     * @param page
     * @param size
     * @return
     */
    @Override
    public ResultDTO getUserMenuInfo(String apply, String page, String size) {

        ResultDTO resultDTO = new ResultDTO();
        try {
            JSONObject json_search = new JSONObject(apply);

            String existName = "0";
            String sql_w = "";

            if (json_search.has("organization_id")) {
                sql_w += " AND organization_id='" + json_search.getString("organization_id") + "'";
            }

            if (json_search.has("member_id")) {
                sql_w += " AND member_id = '" + json_search.getString("member_id") + "'";
            }

            String sqlexit = "select count(1) from member_role where 1=1 ";

            String sqlexit_ok = sqlexit + sql_w;
            existName = getReportingToOne(sqlexit_ok);


            List<String[]> seresult = null;
            List<KamMemberCrpShowDTO> result = null;
            if (!existName.equals("0")) {

                seresult = new ArrayList<String[]>();

                result = new ArrayList<KamMemberCrpShowDTO>();

                //登录sql语句
                String sql = "SELECT member_role_id,member_id,memeber_role_create,member_role_create_time,member_role_modify,member_role_modify_time,sys_role_id FROM member_role WHERE 1=1" + sql_w + " limit " + page + "," + size;

                seresult = this.getReportingTo(sql);

                //构建返回对象
                for (int i = 0; i < seresult.size(); i++) {

                    KamMemberCrpShowDTO km = new KamMemberCrpShowDTO();
                    km.setSys_role_id(seresult.get(i)[7]);

//用member_id拿到sys_role-id的值，去查privailege的值
                    if (seresult.get(i)[7] != null) {

                        List<String[]> menu = new ArrayList<String[]>();

                        List<KamMemberCrpShowDTO> result1 = new ArrayList<KamMemberCrpShowDTO>();

                        String sys_role_id = seresult.get(i)[7];

                        String sql2 = "select role_privilege_id,role_id,privilege_id,role_privilege_create,role_privilege_create_time,role_privilege_modify,role_privilege_modify_time from role_privilege where role_id='" + sys_role_id + "'";

                        seresult = this.getReportingTo(sql2);

                        for (int j = 0; j < seresult.size(); j++) {

                            KamMemberCrpShowDTO kamMemberShowDTO = new KamMemberCrpShowDTO();
                            kamMemberShowDTO.setPrivilege_id(seresult.get(j)[3]);

                            if (json_search.has("member_id")) {
                                //获取该人员权限下的列表

                                String privilege_id = seresult.get(j)[3];

                                ResultDTO menuList;

                                menuList = privilegemenuResource.getPrivilegemenuInfo("{privilege_id:" + seresult.get(j)[3] + "}", "1", "100");

                                kamMemberShowDTO.setSysMenu(menuList.getValues());
                                result.add(kamMemberShowDTO);
                            }

//                 if (seresult.get(j)[3]!=null){
//                     List<String []> menu1 = new ArrayList<String []>();
//
//                     List<KamMemberShowDTO> result2 = new ArrayList<KamMemberShowDTO>();
//
//                     String privilege_id = seresult.get(j)[3];
// //拿到privege的值，查询sys_menu_id值
//
//                     String sql3 = "select privilege_menu_id,privilege_id,sys_menu_id,sys_menu_create,sys_menu_create_time,sys_menu_modify,sys_menu_modify_time,privilege_menu_note from privilege_menu where privilege_id ='"+privilege_id+"'";
//
//                     seresult = this.getReportingTo(sql3);
//
//
//                     for(int y = 0; y < seresult.size(); y++){
//
//                         KamMemberShowDTO kamMemberShowDTO1 = new KamMemberShowDTO();
//
//                         kamMemberShowDTO1.setSys_menu_id(seresult.get(y)[2]);
//                         privilegemenuResource.getPrivilegemenuInfo("{privilege_id:"+seresult.get(y)[3]+"}","1","20");
//
//                     }
//
//                 }

                        }
                    }

                }
            }

            if (result != null && result.size() != 0) {
                resultDTO.setStatus("90000");//
                resultDTO.setDescritpion("用户列表信息调用成功");


            } else {
                resultDTO.setStatus("90001");//
                resultDTO.setDescritpion("用户列表信息调用失败");
            }
            resultDTO.setValues(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return resultDTO;
    }
    //   @Override
//    public ResultDTO updateKamMember(KamMemberPullDTO kamMemberPullDTO) {
//        return null;
//    }
    public String getImage(KamMemberCrpPullDTO kamMemberPullDTO) {
        ResultDTO resultDTO = new ResultDTO();
        // TODO Auto-generated method stub
        String enpenform_image = "";
        //获取配置图片地址
        String[] image_path = this.getImage_path();
        String image_pathAddr = image_path[1];//服务器项目目录地址
        String image_pathSerAddr = image_path[2];//图片访问地址
        String imgDirct = image_pathAddr + "/menu";
        File f = new File(imgDirct);
        if (!f.exists()) {
            f.mkdirs();
            f.setWritable(true, false);
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");

        String imgPath = imgDirct + "/" + uuid + ".png";


        //base64字符串保存为图片
        boolean headImg = FileProcess.GenerateImage(kamMemberPullDTO.getFilestream(), imgPath);
        FileProcess.newlog("执行头像图片储存方法，储存照片地址：" + imgPath + " 方法返回：" + headImg);
        int resultls = 0;
        int mresult = 0;

        String imgurl = "/menu/" + uuid + ".png";

        //ArrayList<HeadPortaitDTO> result = new ArrayList<HeadPortaitDTO>();

        if (headImg) {
            //插入头像表
            enpenform_image += "insert into attachment(attachment_id,attachment_addr,head_portrait_time,file_type,file_name) values ('" + uuid + "','" + imgurl + "','" + df.format(new Date()) + "','" + uuid + ".png" + "','" + uuid + ".png" + "')";
            // enpenform_image += "insert into file(file_id,file_addr,file_time,filegui_id,file_name) values ('" + uuid + "','" +imgurl+ "','" +df.format(new Date()) + "','" + dataDTO.getFilegui_id() + "','" + dataDTO.getFiletype() + "')";
            //执行sql
            resultls = addReportingTo(enpenform_image);
        }

        if (resultls != 0) {
            return uuid;
        }
        return null;
    }

    public String updateImage(KamMemberCrpPullDTO kamMemberPullDTO) {
        // TODO Auto-generated method stub
        String enpenform_image = "";
        //获取配置图片地址
        String[] image_path = this.getImage_path();
        String image_pathAddr = image_path[1];//服务器项目目录地址
        String image_pathSerAddr = image_path[2];//图片访问地址
        String imgDirct = image_pathAddr + "/menu";
        File f = new File(imgDirct);
        if (!f.exists()) {
            f.mkdirs();
            f.setWritable(true, false);
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");

        String imgPath = imgDirct + "/" + uuid + ".png";

        //base64字符串保存为图片
        boolean headImg = FileProcess.GenerateImage(kamMemberPullDTO.getFilestream(), imgPath);
        FileProcess.newlog("执行头像图片储存方法，储存照片地址：" + imgPath + " 方法返回：" + headImg);
        int resultls = 0;
        int mresult = 0;

        String imgurl =  "/menu/" + uuid + ".png";

        //ArrayList<HeadPortaitDTO> result = new ArrayList<HeadPortaitDTO>();

        if (headImg) {
            //修改头像表
            enpenform_image += "update attachment set attachment_addr='" + imgurl + "',head_portrait_time = '" + df.format(new Date()) + "',file_type = '" + uuid + ".png" + "',file_name = '" + uuid + ".png" + "' where attachment_id='" + kamMemberPullDTO.getAttachment_id() + "'";
            // enpenform_image += "insert into attachment(attachment_id,attachment_addr,head_portrait_time) values ('" + uuid + "','" + imgurl + "','" + df.format(new Date()) + "')";
            //执行sql
            resultls = addReportingTo(enpenform_image);
        }


        if (resultls != 0) {
            return uuid;
        }
        return null;
    }


    /**
     * 回调Oa添加方法
     */
    @Override
    public ResultDTO addMhKamMember(KamMemberCrpPullDTO kamMemberPullDTO) {



        try {

            String mhYsytem = "";

            String loginName = kamMemberPullDTO.getMember_name();

            String loginId = kamMemberPullDTO.getNickname();

            String email = kamMemberPullDTO.getMember_email();

            String phone = kamMemberPullDTO.getMember_phone();

            String sex = kamMemberPullDTO.getMember_gender();

            String passWord = kamMemberPullDTO.getMember_password();

           // Long userId = Long.valueOf(kamMemberPullDTO.getUserId());

            JSONObject json  = new JSONObject();
            json.put("loginName",loginName);
            json.put("loginId",loginId);
            json.put("email",email);
            json.put("phone",phone);
            json.put("sex",sex);
            json.put("passWord",passWord);
            //json.put("userId",userId);

            mhYsytem = InternalInterface.postHttp("http://127.0.0.1:8088/rest/userService/oAaddUser", json.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }


        return null;
    }

//    /**
//     * 删除民师系统方法
//     * @param kamMemberPullDTO
//     * @return
//     */
//    @Override
//    public ResultDTO deleteMhKamMemberInfo(KamMemberPullDTO kamMemberPullDTO) {
//
//        try {
//
//            String mhYsytem = "";
//
//
//            Long userId = Long.valueOf(kamMemberPullDTO.getUserId());
//
//
//            JSONObject jsonObject = new JSONObject();
//
//            jsonObject.put("userId",userId);
//
//            mhYsytem = InternalInterface.getHttp("http://127.0.0.1:8080/rest/userService/deleteUser?userId="+userId+"");
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//
//        return null;
//    }
    /**
     * 修改民师系统方法
     * @param kamMemberPullDTO
     * @return
     */
    @Override
    public ResultDTO updateMhKamMember(KamMemberCrpPullDTO kamMemberPullDTO) {
        try {

            String mhYsytem = "";


            Long userId = Long.valueOf(kamMemberPullDTO.getUserId());

            String loginId = kamMemberPullDTO.getMember_name();

            String loginName = kamMemberPullDTO.getNickname();

            String email = kamMemberPullDTO.getMember_email();

            String phone = kamMemberPullDTO.getMember_phone();

            String sex = kamMemberPullDTO.getMember_gender();

            String passWord = kamMemberPullDTO.getMember_password();


            JSONObject jsonObject = new JSONObject();

            jsonObject.put("userId",userId);
            jsonObject.put("loginName",loginName);
            jsonObject.put("loginId",loginId);
            jsonObject.put("email",email);
            jsonObject.put("phone",phone);
            jsonObject.put("sex",sex);
            jsonObject.put("passWord",passWord);

            mhYsytem = InternalInterface.postHttp("http://127.0.0.1:8088/rest/userService/oAupdateUser", jsonObject.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }


        return null;
    }

}
